use std::fs::File;
use std::io::{BufRead, BufReader};
use std::io;

#[allow(unused)]
fn part1(numbers: &Vec<i32>) {
    let result = Iterator::zip(numbers.iter(), numbers.iter().skip(1))
                                 .filter(|(&pre, &next)| next > pre )
                                 .count();

    println!("{}", result);  
}

#[allow(unused)]
fn part2(numbers: &Vec<i32>) {
    let mut three_sums: Vec<i32> = Vec::new();
    for i in 0..(numbers.len() - 2) {
        three_sums.push(
            numbers[i] + numbers[i + 1] + numbers[i + 2]
        );
    }
    let thress_sums = three_sums;

    let result = Iterator::zip(thress_sums.iter(), thress_sums.iter().skip(1))
                                 .filter(|(&pre, &next)| next > pre )
                                 .count();

    println!("{}", result);  
}


fn main() -> io::Result<()> {
    let file = File::open("./day01/input.txt")?;
    let reader = BufReader::new(file);
    let numbers : Vec<i32> = reader.lines()
                                   .into_iter()
                                   .map(|line| line.unwrap().parse().unwrap())
                                   .collect();

    part1(&numbers);
    part2(&numbers);

    Ok(())
}
